home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- CPictureButton.c
-
-
- ******************************************************************************/
-
- #include "CPictureButton.h"
- #include "OSChecks.h"
- #include "Commands.h"
- #include "Global.h"
-
-
- /******************************************************************************
- IPictureButton
-
- Initialize an PictureButton. The pictures are taken from the specified pict
- id resources. You MUST specify pict ids for the standard, disabled, and pressed
- pict resources.
-
- Additionally, you will need to know the width and height of the picture
- button's pict resources.
- ******************************************************************************/
-
- void CPictureButton::IPictureButton( CView *anEnclosure, CBureaucrat *aSupervisor,
- short aHEncl, short aVEncl,short width, short height,
- SizingOption aHSizing, SizingOption aVSizing,
- short pictID, short disabled, short pressed)
- {
- CPicture::IPicture( anEnclosure, aSupervisor,width,height, aHEncl, aVEncl,
- aHSizing, aVSizing);
-
- this->pictID = pictID;
- this->disabledID = disabled;
- this->pressedID = pressed;
- pictH = NULL;
- clickCmd = cmdNull;
- disabledPicH = NULL;
- pressedPicH = NULL;
- active = TRUE;
- IPictureButtonX();
- } /* CPictureButton::IPictureButton */
-
- void CPictureButton::IPictureButtonX(){
- LongRect lRect;
-
- pictH = GetPicture(pictID);
- disabledPicH = GetPicture(disabledID);
- pressedPicH = GetPicture(pressedID);
- UsePICT(pictID);
- SetWantsClicks(active);
- FrameToBounds();
-
- }
-
- void CPictureButton::Activate() {
- if(!active) {
- active = TRUE;
- SetWantsClicks(TRUE);
- DrawPict(FALSE);
-
- }
- inherited::Activate();
-
- }
- void CPictureButton::Deactivate() {
-
- if(active) {
- active = FALSE;
- SetWantsClicks(FALSE);
- DrawPict(FALSE);
- }
- inherited::Deactivate();
-
- }
-
-
- /******************************************************************************
- DrawPict
- Prepare sets up the coordinate system, and macPort.
- Draw draws the correct pict id in the frame.
- ******************************************************************************/
-
- void CPictureButton::DrawPict( Boolean fHilite)
- {
- RGBColor fore, back;
- Rect qdRect;
-
- Prepare();
- if (macPicture && !fHilite) {
- active ? UsePICT(pictID) : UsePICT(disabledID);
- LongToQDRect( &bounds, &qdRect) ;
- //FrameToBounds();
- inherited::Draw(&qdRect);
- }
- else if(fHilite) {
- UsePICT(pressedID);
- LongToQDRect( &bounds, &qdRect) ;
- //FrameToBounds();
- inherited::Draw(&qdRect);
- }
-
- } /* CPictureButton::DrawPicture */
-
- /******************************************************************************
- Draw
-
- Draw the pict in response to an update.
- ******************************************************************************/
-
- void CPictureButton::Draw( Rect *area)
- {
- DrawPict( FALSE);
-
- } /* CPictureButton::Draw */
-
-
- /******************************************************************************
- SetClickCmd
-
- Set the clickCmd for an PictureButton. This command will be sent to
- itsSupervisor when the picture is clicked and the mouse is released
- inside the picture.
- ******************************************************************************/
-
- void CPictureButton::SetClickCmd( long aCmd)
- {
- clickCmd = aCmd;
-
- } /* CPictureButton::SetClickCmd */
-
- /******************************************************************************
- GetClickCmd
-
- Return a CPictureButton's clickCmd
- ******************************************************************************/
- long CPictureButton::GetClickCmd( void)
- {
- return clickCmd;
-
- } /* CPictureButton::GetClickCmd */
-
- /******************************************************************************
- DoClick
-
- Respond to a click. The wantsClicks instance variable must be
- TRUE for this method ever to be called.
- ******************************************************************************/
-
- void CPictureButton::DoClick( Point hitPt, short modifierKeys, long when)
- {
- if (Track())
- {
- itsSupervisor->DoCommand( GetClickCmd());
- }
-
- } /* CPictureButton::DoClick */
-
- /******************************************************************************
- Track
-
- Tracks the mouse, returns TRUE if the mouse was in the Picture when released.
- ******************************************************************************/
-
- Boolean CPictureButton::Track( void)
- {
- Boolean inBtn = TRUE;
- Point where;
- Rect qdFrame;
-
- DrawPict( TRUE);
- LongToQDRect( &frame, &qdFrame);
-
- while (StillDown())
- {
- GetMouse( &where);
- if (PtInRect( where, &qdFrame))
- {
- if (!inBtn) DrawPict( TRUE);
- inBtn = TRUE;
- }
- else
- {
- if (inBtn) DrawPict( FALSE);
- inBtn = FALSE;
- }
- }
- if (inBtn) DrawPict( FALSE);
- return inBtn;
-
- } /* CPictureButton::Track */
-
- /******************************************************************************
- Dispose
-
- ******************************************************************************/
-
- void CPictureButton::Dispose( void)
- {
-
- } /* CPictureButton::Dispose */
-
-
-
- /**** This code is based on the Object I/O code for saving pictures ***/
- /**** If you do not have Object I/O, you can remove everything from here down ***/
- /**** Remember to remove the header prototypes for these routines, too ***/
-
- /**** ------------------* Object I/O *------------------ ****/
- /**** Copyright © 1990, 1992 Object Factory Incorporated ****/
- /**** All rights reserved ****/
-
- typedef struct {
- short pictID;
- short disabledID;
- short pressedID;
- long clickCmd;
- Boolean active;
- } SavePictureButton;
-
-
-
-
- /******************************************************************************
- PutTo
- Object I/O based code, for saving the picture button to a Stream.
- Put the contents of this object to the stream
- ******************************************************************************/
-
- void CPictureButton::PutTo(
- CStream *aStream)
- {
- SavePictureButton s;
-
- s.pictID = pictID;
- s.disabledID = disabledID;
- s.pressedID = pressedID;
- s.clickCmd = clickCmd;
- s.active = active;
- aStream->PutStruct(s);
- inherited::PutTo(aStream);
- }
-
-
- /******************************************************************************
- GetFrom
- Object I/O based code, for getting the picture button from a Stream
-
- Get the contents of this object from the stream and
- initialize the object
- ******************************************************************************/
-
- void CPictureButton::GetFrom(
- CStream *aStream)
- {
- SavePictureButton s;
-
- aStream->GetStruct(s);
- pictID = s.pictID;
- pressedID = s.pressedID;
- disabledID = s.disabledID;
- clickCmd = s.clickCmd;
- active = s.active;
- inherited::GetFrom(aStream);
- IPictureButtonX();
- }
-
-